﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ADDDF.Infrastructure;
using ADDDF.Infrastructure.Test.Support;

namespace ADDDF.Infrastructure.Test
{
    [TestClass]
    public class RepositoryFactoryUnitTest
    {
        #region PartyRepo2

        class PartyRepo2 : RepositoryBase<PartyEntity>, IPartyRepository
        {
            

            public IList<PartyEntity> FindByName(string name)
            {
                throw new NotImplementedException();
            }

            public override PartyEntity FindByKey(object key)
            {
                throw new NotImplementedException();
            }

            public override IEnumerable<PartyEntity> FindAll()
            {
                throw new NotImplementedException();
            }

            public override void Add(PartyEntity item)
            {
                throw new NotImplementedException();
            }

            public override void Remove(PartyEntity item)
            {
                throw new NotImplementedException();
            }

            public override void Change(PartyEntity item)
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        [TestMethod]
        public void RepositoryFactory_Test()
        {
            IPartyRepository repo = RepositoryFactory.Create<IPartyRepository, PartyEntity>();

            Assert.IsNotNull(repo);
        }

        [TestMethod]
        public void RepositoryFactory_Register()
        {
            RepositoryFactory.Register<IPartyRepository, PartyEntity>(typeof(PartyRepo2));

            IPartyRepository repo = RepositoryFactory.Create<IPartyRepository, PartyEntity>();

            Assert.IsInstanceOfType(repo, typeof(PartyRepo2));
            Assert.IsNotNull(repo);

            RepositoryFactory.Unregister<IPartyRepository, PartyEntity>(typeof(PartyRepo2));

            repo = RepositoryFactory.Create<IPartyRepository, PartyEntity>();

            Assert.IsInstanceOfType(repo, typeof(PartyRepository));
            Assert.IsNotNull(repo);
        }

        [TestMethod]
        public void RepositoryFactory_Assembly()
        {
            IFishRepository fishRepo = RepositoryFactory.Create<IFishRepository, Fish>();

            Fish nemo = fishRepo.FindByKey(1);

            Assert.AreEqual(nemo.Name, "Nemo");
        }
    }
}
